package cn.slipi.common.response;

import cn.slipi.common.enums.ResponseCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * lee
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErrorResponse {
    private Integer code;
    private String msg;
    private String exception;

    public static ErrorResponse error(ResponseCode responseCode, Throwable t, String message) {
        ErrorResponse errorResponse = error(responseCode, t);
        errorResponse.setMsg(message);
        return errorResponse;
    }

    public static ErrorResponse error(ResponseCode responseCode, Throwable t) {
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setCode(responseCode.code());
        errorResponse.setMsg(responseCode.msg());
        errorResponse.setException(t.getClass().getName());
        return errorResponse;
    }

}
